/**
 * DAO Factory
 * @author vojta
 */

package DAO;

import core.BlogException;
import java.sql.Connection;

public class DAOFactory {

    Connection cn;
    static DAOFactory instance;

    /**
     * Privatni konstruktor pro inicializaci singletonu
     * @throws BlogSQLException
     */
    private DAOFactory() throws BlogException {
        try {
            cn = MySQLConnector.getConnection();
        } catch (Exception ex) {
            throw new BlogException("Chyba pri pripojovani v DAOFactory!");
        }
    }


    /**
     * Vrati instanci UzivatelDAO
     * @return UzivatelDAO
     */
    public UzivatelDAO getUzivatelDAO() {
        return new UzivatelDAO(cn);
    }
  
    /**
     * Vrati instanci ClanekDAO
     * @return ClanekDAO
     */
    public ClanekDAO getClanekDAO() {
        return new ClanekDAO(cn);
    }
    
    /**
     * Singleton getter
     */
    public static DAOFactory getInstance() throws BlogException{
        if (instance == null)
            instance = new DAOFactory();

        return instance;
    }

}
